package com.huidao.servlet.shoppingcart;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Shoppingcart;
import com.huidao.entity.User;
import com.huidao.service.ShoppingcartService;
import com.huidao.service.ShoppingcartServiceImpl;

/**
 * Servlet implementation class GetShoppingcartListServlet
 */
public class GetShoppingcartListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetShoppingcartListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int currentPage=1;
		if(request.getParameter("currentPage")!=null){
			currentPage=Integer.parseInt(request.getParameter("currentPage"));
		}	
		 ShoppingcartService s=new ShoppingcartServiceImpl();
		 int totalPage=s.getTotalCount();
		if(totalPage>currentPage){
			totalPage=currentPage;
		}
		
		User user=(User) request.getSession().getAttribute("user");
		Long id=user.getUserId();
		List<Shoppingcart>list=s.getAllListPage(currentPage, id);
		//String userShopname=s.getUserShopnameByGoodsId(Long.parseLong(request.getParameter("id")));
		//request.setAttribute("userShopname", userShopname);
		request.setAttribute("list", list);
		request.setAttribute("currentPage", currentPage);
		request.setAttribute("totalPage", totalPage);
		request.getRequestDispatcher("buyershoppingcartlist.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
